package com.owc.controller.admin;

import com.owc.domain.BaseResult;
import com.owc.domain.dto.BalanceDTO;
import com.owc.domain.dto.admin.GasRecommend;
import com.owc.domain.dto.admin.MatchUserDTO;
import com.owc.domain.dto.admin.UserBeanDTO;
import com.owc.domain.dto.admin.UserDetail;
import com.owc.domain.vo.admin.QueryUser;
import com.owc.domain.vo.app.TokenVo;
import com.owc.service.admin.UserManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Author Jackies
 * @Date 2019/12/9 22:46
 * @Description TODO://
 **/
@RestController
@RequestMapping(value = "/admin/userManage")
@Api(tags = "*用户管理")
public class UserManageController {

    private final UserManageService userManageService;

    public UserManageController(UserManageService userManageService) {
        this.userManageService = userManageService;
    }

    @PostMapping(value = "/list")
    @ApiOperation("获取用户列表")
    public BaseResult<List<UserBeanDTO>> userList(@RequestBody QueryUser queryUser){
        return userManageService.userList(queryUser);
    }

    @PostMapping(value = "/userDetail")
    @ApiOperation("获取用户详情")
    public BaseResult<UserDetail> userDetail(@RequestBody QueryUser queryUser){
        Assert.notNull(queryUser.getUserId(),"Please select a user.");
        return BaseResult.success(userManageService.userDetail(queryUser.getUserId()));
    }

    /**
     * 获取钱包余额
     */
    @PostMapping(value = "/getWalletBalance")
    @ApiOperation("获取钱包余额")
    public BaseResult<BalanceDTO> getWalletBalance(@RequestBody @Valid TokenVo tokenVo) throws Exception {
        Assert.notNull(tokenVo.getUserId(),"请选择用户");
        return BaseResult.success(userManageService.getWalletBalance(tokenVo));
    }

    /**
     * 获取推荐燃油费
     */
    @PostMapping(value = "/getRecommendGas")
    @ApiOperation("获取推荐燃油费")
    public BaseResult<GasRecommend> getRecommendGas(){
        return BaseResult.success(userManageService.getRecommendGas());
    }

    @GetMapping(value = "/matchPhone")
    @ApiOperation("(manage-V2)匹配手机号码")
    public BaseResult<MatchUserDTO> matchPhone(@RequestParam @NotNull(message = "手机号码不能为空") String phone){
        return BaseResult.success(userManageService.getUserInfoByPhone(phone));
    }


}
